package com.skymxc.wandroidtodo.page.add;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;


import com.skymxc.wandroidtodo.R;
import com.skymxc.wandroidtodo.databinding.ActivityAddItemBinding;
import com.skymxc.wandroidtodo.page.base.BaseActivity;

/**
 * <p>
 *
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/12/3  7:25 上午
 */
public class AddItemActivity extends BaseActivity<AddItemPresenter> implements AddItemContact.AddItemView, View.OnClickListener {

    private ActivityAddItemBinding mBinding;

    @Override
    protected void initView() {
        super.initView();
        mBinding = ActivityAddItemBinding.inflate(getLayoutInflater());
        setContentView(mBinding.getRoot());
        mBinding.addBtnAdd.setOnClickListener(this);

    }

    @Override
    protected AddItemPresenter initPresenter() {
        return new AddItemPresenter(getApplication());
    }

    @Override
    public void addSuccess() {
        showConfirm("添加成功", false, new DialogListener() {
            @Override
            public void onConfirm() {
                setResult(RESULT_OK);
                finish();
            }

            @Override
            public void onCancel() {

            }
        });
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.add_btn_add) {
            String title = mBinding.addEtTitle.getText().toString();
            if (TextUtils.isEmpty(title)) {
                showConfirm("请输入标题");
                return;
            }
            String content = mBinding.addEtContent.getText().toString();

            mPresenter.addItem(title, content);
        }
    }
}
